package com.sunlands.zlcx.usercenter.vo;

import com.sunlands.zlcx.usercenter.domain.LearnContentDO;
import io.swagger.annotations.ApiModelProperty;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.hibernate.annotations.DynamicInsert;
import org.hibernate.annotations.DynamicUpdate;
import org.springframework.beans.BeanUtils;

import java.io.Serializable;
import java.util.Collections;
import java.util.List;
import java.util.Objects;
import java.util.stream.Collectors;

/**
 * @author shixiaopeng
 */
@Data
@NoArgsConstructor
@AllArgsConstructor
@Builder
@DynamicUpdate
@DynamicInsert
public class LearnContentVO implements Serializable {

    private static final long serialVersionUID = -5142775848079627189L;

    @ApiModelProperty(value = "id")
    private Long id;

    /**
     * 用户表tz_user的id
     */
    private Long userId;

    /**
     * 学习内容
     */
    @ApiModelProperty(value = "学习内容")
    private String content;

    /**
     * 计时分钟数
     */
    @ApiModelProperty(value = "计时分钟数")
    private Integer minutes;

    /**
     * 图标
     */
    @ApiModelProperty(value = "图标")
    private String imageUrl;
    /**
     * @see com.sunlands.zlcx.usercenter.domain.LearnContentDO.ModelEnum
     * 计时模式：1正计时，2倒计时
     */
    @ApiModelProperty(value = "计时模式：1正计时，2倒计时")
    private Integer model;

    @ApiModelProperty(value = "客户端忽略，是否删除，1已删，0未删除")
    private Integer isDelete;

    @ApiModelProperty(value = "学习状态，1未计时，2计时中，12暂停中，13继续中")
    /**
     * {@link com.sunlands.zlcx.usercenter.constant.LearningStatus}
     */
    private Integer status;

    @ApiModelProperty(value = "当日已学习次数")
    private Long curDayCount;

    @ApiModelProperty(value = "背景图url")
    private String backgroundUrl;

    @ApiModelProperty(value = "是否沉浸")
    private Boolean steep;

    @ApiModelProperty(value = "文案")
    private String copy;

    @ApiModelProperty(value = "图标id")
    private Long iconId;

    @ApiModelProperty(value = "背景图id")
    private Long backgroundId;

    @ApiModelProperty(value = "上次使用 1、是 0、否")
    private Integer lastUsed;


    public static LearnContentVO fromDO(LearnContentDO learnContentDO) {
        if (Objects.isNull(learnContentDO)) {
            return null;
        }
        LearnContentVO learnContentDTO = new LearnContentVO();
        BeanUtils.copyProperties(learnContentDO, learnContentDTO);
        
        return learnContentDTO;
    }

    public static List<LearnContentVO> fromDO(List<LearnContentDO> learnContentDOList) {
        if (Objects.isNull(learnContentDOList)) {
            return Collections.emptyList();
        }

        return learnContentDOList.stream()
                .map(LearnContentVO::fromDO)
                .filter(Objects::nonNull)
                .collect(Collectors.toList());
    }

}
